import com.ktjy.entity.CollectionEntity;
import com.ktjy.entity.Host;
import com.ktjy.entity.NullEntity;
import com.ktjy.entity.Pet;
import com.ktjy.service.PetService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

public class Main {
    @Test
    public void test1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Pet pet = (Pet) context.getBean("get1");
        pet.introdce();
    }

    @Test
    public void test2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Pet pet = (Pet) context.getBean("get2");
        pet.introdce();
    }

    @Test
    public void test3() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Pet pet = (Pet) context.getBean("get3");
        pet.introdce();
    }

    @Test
    public void test4() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Pet pet = (Pet) context.getBean("get4");
        pet.introdce();
    }
    @Test
    public void test5() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Host host = (Host) context.getBean("host1");
        System.out.println(host.getName()+","+host.getPet().getName()+","+host.getPet().getAge());
    }

    @Test
    public void test6() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Host host = (Host) context.getBean("host2");
        System.out.println(host.getName()+","+host.getPet().getName()+","+host.getPet().getAge());
    }

    @Test
    public void test7() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Host host = (Host) context.getBean("host3");
        System.out.println(host.getName()+","+host.getPet().getName()+","+host.getPet().getAge());
    }
    @Test
    public void test8(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        CollectionEntity collectionEntity=(CollectionEntity)context.getBean("collectionEntity");

        System.out.println("数组类型："+ Arrays.toString(collectionEntity.getArray()));
        System.out.println("List类型:"+collectionEntity.getList());
        System.out.println("Set类型:"+collectionEntity.getSet());
        System.out.println("Map类型:"+collectionEntity.getMap());
        System.out.println("Properties类型："+collectionEntity.getProps());
    }
    @Test
    public void test9(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        NullEntity nullEntity=(NullEntity) context.getBean("nullEntity");

        System.out.println("emptyValue:"+nullEntity.getEmptyValue());
        System.out.println("nullvalue:"+nullEntity.getNullValue());
    }
    @Test
    public void test10(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        Pet pet=(Pet) context.getBean("get1");
        PetService petService=(PetService) context.getBean("petService");
        petService.save(pet);
    }
}
